package com.wyl.login.activity

import androidx.lifecycle.Observer
import com.wuhenzhizao.titlebar.widget.CommonTitleBar
import com.wyl.libbase.base.BindingActivity
import com.wyl.libbase.utils.CountDownUtils
import com.wyl.libbase.extend.toast
import com.wyl.login.R
import com.wyl.login.databinding.ForgetActivityBinding
import org.koin.android.viewmodel.ext.android.viewModel

class ForgetActivity : BindingActivity<ForgetActivityBinding>() {
    private val viewModel: LoginViewModel by viewModel()

    override fun getLayoutId(): Int = R.layout.forget_activity

    override fun initView() {
        binding.vm = viewModel

        binding.titlebar.setListener { _, action, _ ->
            when (action) {
                CommonTitleBar.ACTION_LEFT_BUTTON -> onBackPressed()
                else -> {
                }
            }
        }

    }

    override fun loadData() {
        viewModel.codeSuccess.observe(this, Observer {
            toast(it ?: "")
            CountDownUtils.changeBtnUi(
                binding.tvGetCode,
                60,
                this.getString(R.string.ui_code_obtain)
            )
        })

        viewModel.success.observe(this, Observer {
            toast(it)
            finish()
        })

        // 注册成功和失败一样的处理
        viewModel.error.observe(this, Observer {
            toast(it ?: "")
        })

    }
}
